/**
 * @overview 创建墙
 * @author dengqiang
 * @description 鲸云CgsWall
 * @update  2022.03.21
 */
class GWall {
  constructor() {
    window.GWallArray = []
  }

  add(paramObj) {
    const { name, option } = paramObj
    const optionModified = {
      positions: option.positions,
      name: option.name || '',
      fill: option.fill || true,
      fillColor: option.fillColor || 'rgba(255, 0, 0, 1.0)',
      outline: option.outline || true,
      outlineColor: 'rgba(255, 0, 0, 1.0)',
      outlineWidth: '1',
      labelfill: option.labelfill || 'rgba(255, 255, 0, 1.0)',
      labelfont: option.labelfont || '24px 微软雅黑',
      labeloffset: option.labeloffset || [0, -15],
      diffHeight: option.diffHeight || 5,
    }
    const wall = new CgsWall(optionModified)
    const wallObject = {
      name: name,
      wall: wall,
    }
    window.map.addFeature(wall)
    window.GWallArray.push(wallObject)
  }

  removeSingleWall(name) {
    window.GWallArray.forEach((item, index) => {
      if (item.name == name) {
        window.GWallArray.splice(index, 1)
        window.map.removeFeature(item.wall)
      }
    })
  }

  setVisible(name, boolean) {
    window.GWallArray.forEach((item, index) => {
      if (item.name == name) {
        item.wall.setVisible(boolean)
      }
    })
  }
}

export default GWall
